package com.medical.admin.hospital.controller;

import com.medical.admin.hospital.common.dto.HospitalDto;
import com.medical.admin.hospital.common.vo.HospitalVo;
import com.medical.admin.hospital.common.vo.PageVo;
import com.medical.admin.hospital.service.HospitalService;
import com.qf.medical.response.ResponseEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * @description: 医院信息管理
 * @author: LuAn
 * @date: 2024/4/26
 */
@Api(tags = "医院信息Api接口文档")
@RestController
@RequestMapping("/hospital")
public class HospitalController {
    @Resource
    private HospitalService hospitalService;

    @GetMapping("/page")
    @ApiOperation("动态分页查询医院信息")
    @ApiImplicitParams({@ApiImplicitParam(name = "hospitalName", value = "医院名称"),
            @ApiImplicitParam(name = "pageNum",value = "当前页"),
            @ApiImplicitParam(name = "pageSize",value = "页大小")})
    public ResponseEntity<PageVo<HospitalVo>> list(String hospitalName,@RequestParam(defaultValue = "1")
            int pageNum, @RequestParam(defaultValue = "10") int pageSize){
         return ResponseEntity.success(hospitalService.list(hospitalName,pageNum,pageSize));
    }

    @ApiOperation("新增医院信息")
    @PostMapping("/add")
    @ApiImplicitParam(name = "hospitalDto" ,value = "医院信息")
    public ResponseEntity<Integer> add(@RequestBody HospitalDto hospitalDto){
          return ResponseEntity.success(hospitalService.insert(hospitalDto));
    }

    @ApiOperation("修改医院信息")
    @PutMapping("/modify")
    @ApiImplicitParam(name = "hospitalDto" ,value = "医院信息")
    public ResponseEntity<Integer> modify(@RequestBody HospitalDto hospitalDto){
        return ResponseEntity.success(hospitalService.update(hospitalDto));
    }

    @ApiOperation("删除医院信息")
    @DeleteMapping("/remove")
    @ApiImplicitParam(name = "hospitalId" ,value = "医院ID")
    public ResponseEntity<Integer> remove(@NotNull Long hospitalId){
        return ResponseEntity.success(hospitalService.delete(hospitalId));
    }

    @ApiOperation("查询医院信息详情")
    @GetMapping("/detail")
    public ResponseEntity<HospitalVo> detail(@NotNull Long hospitalId){
        return ResponseEntity.success(hospitalService.select(hospitalId));
    }
}
